/********************************************************************************************************
/*
/*    SettingsBase.h
/*
/********************************************************************************************************/

#pragma once



//======================================================================================================================
// CLASSES
//======================================================================================================================

class cFileIn;
class cFileOut;

//----------------------------------------------------------------------------------------------------------------------
//  CLASS SETTINGS BASE
//----------------------------------------------------------------------------------------------------------------------
class cSettingsBase
{
public:
	enum				_eType { novalue=0, boolean, integer, uint, version, string, rect_i, point_i };
	void				save_to_file ();
	bool				load_from_file();
	void				set_pathname ( const wchar_t * pArg ) { sPathname = pArg; }
	void				restore_defaults();
	cVersion		    PrevVersion; // the version that created the loaded settings file

	bool 				get_val_from_name ( void ** ppRetVal, _eType * pRetType, const wchar_t * pName ); // used by cDlgVars
	bool				set_val_from_name ( const wchar_t * pName, const void * pNewVal, _eType eType = novalue );
	bool				set_val_from_name ( const wchar_t * pName, bool bNewVal ); // used by cDlgVars

protected:

	struct sEntry
	{
		int				offset; // offset of address of item from start of struct
		_eType			type;   // type
		const wchar_t *	name;   // name
	};

	void				write_item ( cFileOut * pFile, const wchar_t * pName, const wchar_t * pValue );
	void *				entry_to_item ( sEntry * e ) { return (void *) ( (BYTE*)this + e->offset ); }
	sEntry * 			name_to_entry ( const wchar_t * pName );
	cStrW		        sPathname; // fully qualified name of file

	//-----------------------------------
	// DEFINE FOLLOWING IN DERIVED CLASS
	//-----------------------------------

	virtual sEntry * 	table ( int i = 0 ) = 0;
	virtual int			qty_entries () = 0;
	virtual void		init () = 0;

};

